﻿
@{
    ViewBag.Title = "流程明细";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<style type="text/css">
    .form .formValue input.form-control {
        height: 32px;
        line-height: 32px;
        padding: 0px;
        resize: none;
        border-radius: 0px;
        box-shadow: none;
        text-indent: 5px
    }

    .textValue {
        width: 100%;
    }

    .selectbox {
        color: #444;
        line-height: 34px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 34px;
        width: 100%;
    }

    .search {
        margin-left: 10px;
        padding: 0px;
    }

    table td {
        height: 40px;
        line-height: 40px;
    }

    .zdyPanel {
        background-color: #fff;
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        border-right: 1px solid #ddd;
        margin: 0px;
        float: left;
        width: 100%;
    }

    .zdyTool {
        float: left;
        padding-left: 10px;
        width: 100%;
    }

    .zdyBar {
        padding: 0px;
        margin: 0px;
        margin-top: 3px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        width: 100%;
        margin: 0px;
        padding: 0px;
        float: left;
    }

    .zdyContentPanel {
        width: 100%;
        margin: 5px 0px 0px 0px;
        padding: 0px;
        float: left;
    }

    .zdyFont {
        padding-left: 5px;
        color: #ff6a00;
    }

    .autocomplete-suggestions {
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        border: 1px solid #999;
        background: #FFF;
        cursor: default;
        overflow: auto;
        -webkit-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        -moz-box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
        box-shadow: 1px 4px 3px rgba(50, 50, 50, 0.64);
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-no-suggestion {
        padding: 2px 5px;
    }

    .zdyUL {
        list-style-type: none;
        margin: 5px 0px 0px -3px;
        padding: 0px;
    }

        .zdyUL li {
            float: left;
            list-style: none;
            height: 24px;
            line-height: 22px;
        }

            .zdyUL li a {
                cursor: pointer;
                padding: 5px 10px;
                border-radius: 4px;
            }

            .zdyUL li i {
                margin-right: 4px;
                font-size: 13px;
                color: #666;
                vertical-align: middle;
                margin-top: -1px;
            }

            .zdyUL li a:hover {
                text-decoration: none;
                background-color: #1ABC9C;
                color: #fff;
            }

    .zdyGirdPanel {
        padding-top: 3px;
    }

    .form .formValue {
        padding: 1px 3px;
    }
</style>
<script>
    var resultData;
    var workFlowId = $.request("keyValue");


    $(function () {
        $("#state_horizon a.btn-default").click(function () {
            $("#state_horizon a.btn-default").removeClass("active");
            $(this).addClass("active");
            $('#btn_search').trigger("click");
        });


        GetItems();
        gridList();
    });

    //function GetInit() {
    //    $.ajax({
    //        url: "/WorkFlowSetting/FlowManage/GetDetailItemsJson",
    //        dataType: "json",
    //        async: false,
    //        success: function (data) {
    //            resultData = data;
    //            InitControl();
    //        }, error: function (XMLHttpRequest, textStatus, errorThrown) {
    //        }
    //    });
    //}

    function GetItems() {
        $.ajax({
            url: '/WorkFlowSetting/FlowManage/GetDetailItemsJson',
            dataType: "json",
            async: false,
            success: function (data) {
                resultData = data;
                InitControl();
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    }

    function InitControl() {
        var F_WorkFormId = resultData.F_WorkFormId,
            html = "";
        for (var i = 0; i < F_WorkFormId.length; i++) {
            html += "<option value='" + F_WorkFormId[i].F_ItemCode + "'>" + F_WorkFormId[i].F_ItemName + "</option>";
        }

        $("#F_WorkFormId").append(html);
        // $("#F_WorkFormId").append(html).bindSelect();
        //debugger
        //$('#F_WorkFormId').val('lc1001');
        //var F_ActivityType = resultData.F_ActivityType;
        //for (var i = 0; i < F_ActivityType.length; i++) {
        //    $("#F_ActivityType").append("<option value='" + F_ActivityType[i].F_ItemCode + "'>" + F_ActivityType[i].F_ItemName + "</option>");
        //}
    }

    function gridList() {
        var $gridList = $("#gridList");
        var queryJson = {};
        $gridList.dataGrid({
            url: "/WorkFlowSetting/FlowManage/GetDetailGridJson",
            postData: { queryJson: JSON.stringify(queryJson), keyValue: workFlowId },
            height: 630,
            colModel: [
                {
                    label: '步骤名称', name: 'F_StepName', width: 100, formatter: function (cellvalue) {
                        return cellvalue;
                    }
                },
                {
                    label: '流程序号', name: 'F_WorkFlowNo', width: 50, formatter: function (cellvalue) {
                        return cellvalue;
                    }
                },
                {
                    label: '超期提示', name: 'F_TimeOutTip', align: 'left', width: 100, formatter: function (cellvalue) {
                        return cellvalue;
                    }
                },
                {
                    label: '指定完成工时（小时）', name: 'F_WorkHours', align: 'left', width: 120, formatter: function (cellvalue) {
                        return cellvalue;
                    }
                },
                {
                    label: '超时处理', name: 'F_TimeOutOpreation', align: 'left', width: 80, formatter: function (cellvalue) {
                        //var timeOutOpreation = resultData.F_TimeOutOpreation;

                        //for (var i = 0; i < timeOutOpreation.length; i++) {
                        //    if (timeOutOpreation[i].F_ItemCode == cellvalue) {
                        //        return timeOutOpreation[i].F_ItemName;
                        //    }
                        //}

                        //return '';
                        return cellvalue;
                    }
                },
                {
                    label: '超时处理方式', name: 'F_OpreationType', align: 'left', width: 100, formatter: function (cellvalue) {

                        return '';
                    }
                },
                {
                    label: '处理人', name: 'F_OpreationUsers', align: 'left', width: 100, formatter: function (cellvalue) {
                        return cellvalue;
                    }
                },
                {
                    label: '处理策略', name: 'F_OpreationStrategy', align: 'left', width: 100, formatter: function (cellvalue) {
                        //var opreationStrategy = resultData.F_OpreationStrategy;

                        //for (var i = 0; i < opreationStrategy.length; i++) {
                        //    if (opreationStrategy[i].F_ItemCode == cellvalue) {
                        //        return opreationStrategy[i].F_ItemName;
                        //    }
                        //}

                        //return '';
                        return cellvalue;
                    }
                },
                {
                    label: '退回策略', name: 'F_ReturnStrategy', align: 'left', width: 100, formatter: function (cellvalue) {
                        //var returnStrategy = resultData.F_ReturnStrategy;

                        //for (var i = 0; i < returnStrategy.length; i++) {
                        //    if (returnStrategy[i].F_ItemCode == cellvalue) {
                        //        return returnStrategy[i].F_ItemName;
                        //    }
                        //}

                        //return '';
                        return cellvalue;
                    }
                },
                {
                    label: '退回类型', name: 'F_ReturnType', align: 'left', width: 100, formatter: function (cellvalue) {
                        //var returnType = resultData.F_ReturnType;

                        //for (var i = 0; i < returnType.length; i++) {
                        //    if (returnType[i].F_ItemCode == cellvalue) {
                        //        return returnType[i].F_ItemName;
                        //    }
                        //}

                        //return '';
                        return cellvalue;
                    }
                },
                {
                    label: '抄送人', name: 'F_CcUserId', align: 'left', width: 100, formatter: function (cellvalue) {
                        return cellvalue;
                    }
                },
                {
                    label: '通知方式', name: 'F_MessageSend', align: 'left', width: 150, formatter: function (cellvalue) {

                        //var messageSend = resultData.F_MessageSend;

                        //for (var i = 0; i < messageSend.length; i++) {
                        //    if (messageSend[i].F_ItemCode == cellvalue) {
                        //        return messageSend[i].F_ItemName;
                        //    }
                        //}

                        //return '';
                        return cellvalue;
                    }
                },
                {
                    label: '操作', name: 'F_WorkFlowDetailId', width: 120, align: 'center',
                    formatter: function (cellvalue, options, rowObject) {
                        return '<div class="btn-group btn-group-xs" style="margin-top:5px;">'
                            + '   <button type="button" class="btn btn-info" onclick="btn_detail(\'' + cellvalue + '\', 0)">编辑</button>'
                            + '   <button type="button" class="btn btn-danger" onclick="btn_delete(\'' + cellvalue + '\')">删除</button>'
                            + '</div>';
                    }
                },
                { label: '', name: 'F_WorkFlowDetailId', hidden: true },
                { label: '', name: 'F_WorkFlowId', hidden: true }
            ],
            pager: "#gridPager",
            viewrecords: true,
            multiselect: false,
            sortname: 'F_Id',
            ondblClickRow: function (rowid, iRow, iCol, e) {
                var rowobj = $("#gridList").jqGridRowValue();
                if (rowobj["F_OrderState"] == 0 || rowobj["F_OrderState"] == -1) {
                    btn_Update();
                } else {
                    Detail();
                }
            },
            loadComplete: function (data) {

                $('#F_WorkFlowName').val(data.workFlow.F_WorkFlowName);
                $('#F_WorkFormId').val(data.workFlow.F_WorkFormId);

            }
        });
    }

    function Detail() {
        var rowobj = $("#gridList").jqGridRowValue();
        if (rowobj.F_WorkFlowDetailId) {
            $.modalOpen({
                id: "editForm",
                title: "详情",
                url: '/WorkFlowSetting/FlowManage/Form?workFlowId=' + workFlowId + '&keyValue=' + rowobj.F_WorkFlowDetailId + '&workFlowName=&state=detail',
                width: "800px",
                height: "350px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                },
                btn: null
            });
        } else {
            $.modalAlert("请选中行数据！", "warning");
        }
    }

    function GetDictionaries(value, type) {
        if (type == "F_SiteType") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_SiteType.length; i++) {
                if (value == resultData.F_SiteType[i].F_ItemCode) {
                    return resultData.F_SiteType[i].F_ItemName;
                }
            }
            return '';
        } else if (type == "F_ActivityCityId") {
            var strHtml = "";
            for (var i = 0; i < resultData.F_ActivityCityId.length; i++) {
                for (var j = 0; j < value.split(',').length; j++) {
                    if (j == value.split(',').length - 1) {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName;
                        }
                    } else {
                        if (value.split(',')[j] == resultData.F_ActivityCityId[i].F_ItemCode) {
                            strHtml += resultData.F_ActivityCityId[i].F_ItemName + ",";
                        }
                    }
                }
            }
            return strHtml;
        } else if (type == "F_ActivityType") {
            for (var i = 0; i < resultData.F_ActivityType.length; i++) {
                if (value == resultData.F_ActivityType[i].F_ItemCode) {
                    return resultData.F_ActivityType[i].F_ItemName;
                }
            }
            return '';
        }
    }

    function btn_onSearch() {
        var $gridList = $("#gridList");
        var queryJson = {
            F_DemandCash: $("#F_DemandCash").val(),
            F_ActivityCityId: $("#F_CityId").val(),
            F_ActivityType: $("#F_ActivityType").val(),
            F_ClientName: $("#F_ClientName").val(),
            F_ActivityStartDate: $("#F_ActivityStartDate").val(),
            F_CreatorTime: $("#F_CreatorDate").val(),
            F_State: $("#state_horizon a.active").attr('data-value')
        };
        $gridList.jqGrid('setGridParam', {
            postData: { queryJson: JSON.stringify(queryJson) },
        }).trigger('reloadGrid');
    }

    function btn_Add() {
        //var workFlowName = $('#F_WorkFlowName').val();

        //if (workFlowName == null || workFlowName == '') {
        //    $.modalAlert("请先填写流程名称！", "warning");
        //    return;
        //}

        //var workFormId = $('#F_WorkFormId').val();

        //if (workFormId == null || workFormId == '') {
        //    $.modalAlert("请先选择流程表单！", "warning");
        //    return;
        //}

        $.modalOpen({
            id: "addForm",
            title: "新建流程",
            url: '/WorkFlowSetting/FlowManage/Form?workFlowId=' + workFlowId + '&state=add',
            width: "800px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].$("#gridList").trigger("reloadGrid");
                var result = top.frames[iframeId].submitForm();
                
                if (result == undefined) {
                    $.closeTab();
                }

                //alert(top.frames[iframeId]);
                // $.frames['0000-0000-0000'].$("#gridList").trigger("reloadGrid");
            }
        });
    }

    function btn_delete(id) {
        $.modalConfirm('确定删除吗？', function (flag) {
            if (flag) {
                $.submitForm({
                    url: "/WorkFlowSetting/FlowManage/DeleteWorkFlowDetail?keyValue=" + id,
                    param: {},
                    success: function (data) {
                        $.currentWindow().$("#gridList").trigger("reloadGrid");
                    }
                });
            }
        });

        //$('a[class="layui-layer-btn1 btn btn-danger"]').trigger('click');
    }

    function btn_Update() {
        //var rowobj = $("#gridList").jqGridRowValue();
        //console.log(222);
        //if (rowobj.F_Id) {
        //    $.modalOpen({
        //        id: "editForm",
        //        title: "编辑流程",
        //        url: '/WorkFlowSetting/FlowManage/Form?workflowid=' + '8b0cf2f1-30ce-11e8-bc3f-00163e00446b' + '&workflowdetailid=' + '8b0cf2f1-30ce-11e8-bc3f-00163e00441b',
        //        width: "1200px",
        //        height: "300px",
        //        callBack: function (iframeId) {keyValue
        //            top.frames[iframeId].submitForm();
        //        }
        //    });
        //} else {
        //    $.modalAlert("请选中行数据！", "warning");
        //}
    }

    function btn_detail(id) {
        //var workFlowName = $('#F_WorkFlowName').val();

        //if (workFlowName == null || workFlowName == '') {
        //    $.modalAlert("请先填写流程名称！", "warning");
        //    return;
        //}

        $.modalOpen({
            id: "GiveSingle",
            title: "编辑流程",
            url: '/WorkFlowSetting/FlowManage/Form?workFlowId=' + workFlowId + '&keyValue=' + id ,
            width: "800px",
            height: "350px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

</script>
<div class="zdyPanel">
    @*<div class="zdyBar" style="float:left;white-space:nowrap;width:50%;">
        <div class="search">
            <table class="form" style="width:300px;">
                <tr>
                    <td class="formValue" style="width: 150px;">
                        <input type="text" id="F_WorkFlowName" class="form-control textValue" placeholder="流程名称" />
                    </td>
                    <td class="formValue" style="width: 150px;">
                        <select id="F_WorkFormId" name="F_WorkFormId" class="selectbox">
                            <option value="">==流程表单==</option>
                        </select>
                    </td>
                </tr>

            </table>
        </div>
    </div>*@
    <div class="zdyBar" style="float:right;white-space:nowrap;width:50%;padding-top:5px;">
        <div style="float:right;">
            <div class="btn-group">
                <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            </div>
            <div class="btn-group">
                <a class="btn btn-primary" onclick="btn_Add()"><i class="fa fa-eraser">新建步骤</i></a>
            </div>
            @*<div class="btn-group">
                    <a class="btn btn-primary" onclick="btn_Update()"><i class="fa fa-pencil-square-o">编辑需求</i></a>
                </div>*@
        </div>
    </div>
</div>
<div class="zdyGirdPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
